<script setup lang='ts'>
import consola from 'consola'
import { onMounted } from 'vue';
import { useDataStore } from '@/store/data'
import useTree from '@/composables/primevue/useTree'

const dataStore = useDataStore()
const {
    treeValue,
    treeTableValue,
    selectedTreeValue,
    selectedTreeTableValue
} = useTree()


function updateTableData() {
    treeValue.value = dataStore.treenodesData as Array<any>
    treeTableValue.value = dataStore.treetablenodesData as Array<any>
}

// mounted
onMounted(async () => {
  await dataStore.$load({ name: 'app-data' }).catch((error: any) => consola.error(error))
  updateTableData()
})
</script>

<template>
    <div class="grid">
        <div class="col-12">
            <div class="card">
                <h5>Tree</h5>
                <h6>Basic</h6>
                <Tree :value="treeValue" class="w-full md:w-30rem"></Tree>
                <h6>Checkbox</h6>
                <Tree :value="treeValue" selectionMode="checkbox" v-model:selectionKeys="selectedTreeValue"></Tree>
                <h6>Filter</h6>
                <Tree :value="treeValue" :filter="true" filterMode="lenient" class="w-full md:w-30rem"></Tree>
            </div>
        </div>
        <div class="col-12">
            <div class="card">
                <h5>TreeTable</h5>
                <TreeTable :value="treeTableValue" selectionMode="checkbox" v-model:selectionKeys="selectedTreeTableValue">
                    <template #header> FileSystem </template>
                    <Column field="name" header="Name" :expander="true"></Column>
                    <Column field="size" header="Size"></Column>
                    <Column field="type" header="Type"></Column>
                </TreeTable>
            </div>
        </div>
    </div>
</template>
